home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / VideoToolbox 96.06.15 / VideoToolboxSources / GetClicks.c < prev    next >
Text File  |  1996-06-07  |  2KB  |  62 lines

  1. /*
  2. GetClicks.c
  3. waits for a mouse click, and then counts clicks (e.g. double-click, triple-click). Each
  4. click must arrive within the acceptable double-click time of the previous,
  5. as set in the Control Panel. Returns the number of clicks, 1 or more.
  6. Aborts if the user hits Command-period.
  7. Calls SndStop1() immediately after the first click on the assumption that the user is
  8. responding to the sound and should get the feedback of knowing that the computer knows
  9. s/he's now responding. SndStop1() is innocuous if in fact no sound is playing.
  10.  
  11. HISTORY:
  12. 4/30/88 dgp    wrote it
  13. 3/31/90    dgp    cleaned up code and documentation.
  14. 8/24/91    dgp    Made compatible with THINK C 5.0.
  15. 3/30/91    dgp    use SndStop1() instead of obsolete Sound Driver.
  16. 1/25/93 dgp removed obsolete support for THINK C 4.
  17. 4/29/95 dgp added GetNextEventOrQuit(), so that we can abort at any time by hitting Command-.
  18. 6/18/95 dgp changed abort() to exit(1) for better compatibility with CW atexit().
  19. 6/6/96 dgp replaced US-only test by IsCmdPeriod() test, which will work internationally.
  20. 6/7/96  dhb use PrintfExit so it will work in a MEX file.
  21.         dhb Fixed GetNextEventOrQuit so it compiles.  It referenced an undefined variable.
  22. */
  23. #include "VideoToolbox.h"
  24.  
  25. short GetClicks(void)
  26. {
  27.     long ticks;
  28.     EventRecord event;
  29.     short clicks;
  30.  
  31.     clicks=0;
  32.     while(!GetNextEventOrQuit(mDownMask,&event)) ;
  33.     SndStop1();    /* Stop sound on first click */
  34.     clicks++;
  35.     ticks=TickCount()+GetDblTime();
  36.     while(!GetNextEventOrQuit(mUpMask,&event)) ;
  37.     while(TickCount() < ticks)    /* wait as long a possible for another click */
  38.         if(GetNextEventOrQuit(mDownMask,&event)){
  39.             clicks++;
  40.             ticks=TickCount()+GetDblTime();
  41.             while(!GetNextEventOrQuit(mUpMask,&event)) ;
  42.         }
  43.     return clicks;
  44. }
  45.  
  46. short GetNextEventOrQuit(int mask,EventRecord *eventPtr)
  47. {
  48.     if(GetNextEvent(mask|keyDownMask,eventPtr))switch(eventPtr->what){
  49.     case keyDown:
  50.         if(IsCmdPeriod(eventPtr)){
  51.             #if MATLAB
  52.                 PrintfExit("GetClicks: User typed cmd-. EXITING.");
  53.             #else
  54.                 PrintfExit("\nGetClicks: User typed cmd-. EXITING.\n");
  55.             #endif
  56.         }
  57.         return (mask&keyDownMask)!=0;
  58.     default:
  59.         return 1;
  60.     }else return 0;
  61. }
  62.